/**
 * Create by richliu1023
 * @date 16/5/19
 * @email richliu1023@gmail.com
 * @github https://github.com/RichLiu1023
 * @description a simple explanation
 */
class WorldControl {

	private static _worldCvs:WorldCanvas;
	private static _stat;
	private static _isSetup:boolean = false;

	public static setup():void {
		if ( this._isSetup )return;
		this._isSetup = true;
		this._worldCvs = new WorldCanvas();//初始化3d画布
		LightControl.setup();//启动光照
		rm.CameraController.setup( this._worldCvs.camera3D );

		this._worldCvs.canvas3d.start();

		//this._stat = new Stats();
		//this._stat.setMode(0);
		//
		//var player = document.getElementsByClassName('egret-player');
		//player[0].appendChild(this._stat.domElement);
		//this._stat.begin();

		this.setupEventListener();

	}

	private static setupEventListener():void {
		this._worldCvs.canvas3d.addEventListener( egret3d.Event3D.ENTER_FRAME, this.onEnterFrame, this );
	}

	public static addChild3D( $child3d:egret3d.Object3D ):void {
		this._worldCvs.addChild3D( $child3d );
	}

	public static removeChild3D( $child3d:egret3d.Object3D ):void {
		this._worldCvs.removeChild3D( $child3d );
	}

	public static onEnterFrame( $e:egret3d.Event3D ):void {
		//this._stat.update();
		EventController.dispatchEvent( GameEvent.ENTER_FRAME );
		rm.CameraController.update();
	}

	public static addSky( mate:egret3d.CubeTexture ):void {
		//var sky:egret3d.Sky = new egret3d.Sky( new egret3d.CubeTextureMaterial( mate ), this._worldCvs.camera3D );
		//this._worldCvs.addChild3D( sky );
	}

}